<?php
/**
 * Created by PhpStorm.
 * User: L
 * Date: 2018/11/27
 * Time: 15:57
 */

namespace app\models\Project_1_0;


use Core\Model;

class Rice_intf extends Model
{
    function userinfo()
    {

        $sql = "select * from tbl_user";
        $res = $this->db->getRow($sql);
        return $res;

    }

    function banner_intf()
    {
        //轮播图
        $sql = "select * from tbl_banner";
        $res = $this->db->fetch_sql($sql);
        return $res;

    }

    function goods_details()
    {
        //查询所有商品
        $sql = "select * from tbl_goods";
        $res = $this->db->fetch_sql($sql);
        return $res;

    }

    function search_goods()
    {
        //查询一条商品详情
        $goods_id = $_GET['goods_id'];
        $sql = "select * from tbl_goods where goods_id={$goods_id}";
        $res = $this->db->getRow($sql);
        return $res;


    }

    function cart()
    {
        //添加购物车
        $cart_user_id=$_GET['user_id'];//用户id
        $cart_total = $_GET['total'];//单价
        $cart_amount = $_GET['amount'];//数量
        $cart_total_amount = $cart_total * $cart_amount;

        $sql = "insert into tbl_cart (cart_user_id,cart_total,cart_amount,cart_total_amount )value ({$cart_user_id},{$cart_total},{$cart_amount},{$cart_total_amount})";
        $res = $this->db->exec_sql($sql);
        return $res;


    }
    function search_cart(){
        //购物车
        $cart_goods_id = $_GET['id'];
        $sql1 = "select * from tbl_cart where cart_goods_id={$cart_goods_id}";
        $res = $this->db->fetch_sql($sql1);
        return $res;
    }
    function add_address(){
        $name=$_GET['name'];//收货人姓名
        $tel=$_GET['tel'];//收货人手机
        $address=$_GET['address'];//收货人地址
        $sql="insert into tbl_address (address_name,address_tel,address_address) values ({$name},{$tel},{$address})";
        $res = $this->db->exec_sql($sql);
        return $res;

    }
    function search_address(){
        //查询地址
        $sql="select * from tbl_address";
        $res=$this->db->fetch_sql($sql);
        return $res;
    }
    function add_order(){
        $amount=$_GET['amount'];
        //订单订单总金额:该订单所有商品合计
        $pay_time=$_GET['paytime'];
        //支付时间
        $status=$_GET['status'];
        //支付状态 0待确认 1待支付 2已支付 3已发货 4已完成
        $recipient_name=['recname'];
        //收件人名字
        $recipient_tel=['rectel'];
        //收件人电话
        $recipient_address=['recadd'];
        //收件人地址 精确到门牌号
        $remark=['remark'];
        //订单备注
        $sql="insert into tbl_order (order_total_amount,order_pay_time,order_status,order_recipient_name,order_recipient_tel,order_recipient_address,order_remark) 
        values ({$amount},{$pay_time},{$status},{$recipient_name},{$recipient_tel},{$recipient_address},{$remark})";
        $res = $this->db->exec_sql($sql);
        return $res;

    }
}